<template>
	<!-- <uni-search-bar @confirm="searchCityBus" v-model="searchKey" /> -->
	<uni-search-bar @confirm="searchCityBus" :focus="true" v-model="searchKey" @blur="blur" @focus="focus"
		@input="input" @cancel="cancel" @clear="clear">
	</uni-search-bar>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		CONFIG
	} from '../../utils/config';
	import {
		userStore
	} from '../../store/userStore';

	onLoad(() => {
		getPos()
	})


	let stroe = userStore()

	let searchKey = ref('')

	function searchCityBus() {
		if (searchKey.value == "") {
			uni.showToast({
				title: '请输入关键字',
				icon: 'none'
			})
		} else {
			let url = `https://uri.amap.com/line?name=${searchKey.value}&city=029&callnative=0`
			window.location.href = url
		}
	}


	function getPos() {
		uni.getLocation({
			success: function(res) {
				console.log('当前位置的经度：' + res.longitude);
				console.log('当前位置的纬度：' + res.latitude);
				// 将定位保存到状态库
				store.savePos(res.longitude, res.latitude)
				console.log(store.currentPos)
			}
		});
	}
</script>

<style scoped lang="scss">

</style>